
var F_Activity_Entrance = {
    _init: function () {
        console.log("初始化活跃玩家");

        if (B_Login._checkUpdate(), M_HeadFoot._headShow(1), "demo" != M_Init._controller && B_User._isDemoUser())
            B_Login._openLogin("background");
        else {
            console.log("活跃玩家真实数据")
            switch (M_Init._clean(), M_Init._controller) {
                case"demo":
                    M_Init._api.innerOperationActiveUser = "demoInnerOperationActiveUser";
                    break;
                default:
                    M_Init._api.innerOperationActiveUser = "innerOperationActiveUser"
            }

            M_Init._dateCache.begin = M_Init._dateChoose.begin,
                M_Init._dateCache.end = M_Init._dateChoose.end,
                M_Common._getOrderGame("activity", "", "1-2-2"),

                B_Date._chooseSection({
                autoCommit: !1,
                todayValid: !1
            }, 1, M_Init._dateChoose.begin, M_Init._dateChoose.end, function (t, a) {
                console.log("插入活跃玩家数据")
                t == M_Init._dateCache.begin && M_Init._dateCache.end == a || (M_Init._dateCache.begin = t, M_Init._dateCache.end = a, F_Activity_Info._getInfo())
            })
        }
    }
}, F_Activity_Info = {
    _init: [{
        type: "togetherTabAvg",
        name: "活跃度指标",
        tab: ["DAU", "WAU", "MAU"],
        tips: [{}, {
            position: "second",
            content: ["当日开启过游戏的玩家人数", "当日最近一周（含当日向前推7日）开启过游戏的玩家人数", "当日最近一月（含当日向前推30日）开启过游戏的玩家人数"]
        }]
    }, {
        type: "switch",
        name: "已玩天数分布",
        tab: [],
        tips: [{position: "first", content: "所选时期的活跃玩家的活跃日期减新增日期的日数差（即其已进行游戏的天数）的分布情况"}]
    }, {
        type: "switch",
        name: "等级分布",
        tab: [],
        tips: [{position: "first", content: "所选时期每日活跃玩家的等级分布情况"}]
    }, {
        type: "regionTab",
        name: "地区分布",
        tab: ["中国地区", "全球地区"],
        tips: [{}, {position: "second", content: ["所选时期活跃玩家的地区分布情况", "所选时期活跃玩家的地区分布情况"]}]
    }],
    _avg: [[[{label: "AVG：", name: "平均每日活跃用户数量", key: "avg_dau", unit: ""}], [{
        label: "AVG：",
        name: "平均每周活跃用户数量",
        key: "avg_wau",
        unit: ""
    }], [{label: "AVG：", name: "平均每月活跃用户数量", key: "avg_mau", unit: ""}]]],
    _port: [[[{name: "DAU", key: "y_axis_dau"}], [{name: "WAU", key: "y_axis_wau"}], [{
        name: "MAU",
        key: "y_axis_mau"
    }]], [[{name: "已玩天数", key: "login_user_oldays_distri"}]], [[{
        name: "玩家等级分布",
        key: "login_user_level_distri"
    }]], [[{name: "国内地区分布", key: "area_distri|china"}], [{name: "国际地区分布", key: "area_distri|global"}]]],
    _domInit: function () {
        console.log("_domInit")
        M_Inside._htmlChartTable($("#ct_main_area"), F_Activity_Info._init),
            M_Inside._downloadCsv(),
            F_Activity_Info._getInfo()
    },
    _getInfo: function () {

        console.log("_getInfo M_Init._dateCache.begin",M_Init._dateCache.begin )
        console.log("_getInfo M_Init._dateCache.begin",M_Init._dateCache.end )
        console.log("_getInfo F_Activity_Info._init.length",F_Activity_Info._init.length )


        for (var t = M_Init._dateCache.begin, a = M_Init._dateCache.end, e = [], i = 0; i < F_Activity_Info._init.length; i++)
            e.push("bs_chart_" + i + "_0");

        console.log("e is:",e);
        console.log("t is:",t);
        console.log("M_Init._api.innerOperationActiveUser is:",M_Init._api.innerOperationActiveUser);
        console.log("e[t] is:",e[t]);

        var _ = {};
        _.start_date = t,
            _.end_date = a,
            _.game_id = M_Init._gameId,
            _ = B_Common._postData(_),
            B_Port._ajax(M_Init._api.innerOperationActiveUser, "post", !0, _, function () {
            for (var t = 0; t < e.length; t++){
                $("#" + e[t]).html(B_Pre._loading())
               // console.log("33333",$("#" + e[t]))
            }
        }, function () {
            for (var t = 0; t < e.length; t++){
                $("#" + e[t]).html("")
            }

        }, function (t, a) {
                console.log("t is:",t);

            if (t) {
                M_Init._dataCache.data = t;

                console.log("  F_Activity_Info._init.length is:", F_Activity_Info._init.length);
                for (var e = 0; e < F_Activity_Info._init.length  ; e++){
                    if (F_Activity_Info._init[e].tab.length > 0) {
                        M_Init._dataCache["position_" + e] || (M_Init._dataCache["position_" + e] = 0);
                        for (var i = 0; i < F_Activity_Info._init[e].tab.length; i++)
                            if (M_Init._dataCache["position_" + e] == i) {
                                F_Activity_Info._chartHtml(e, i),
                                    M_Inside._chartTableIcon(F_Activity_Info._init[e].type, e, i);
                                break
                            }
                        M_Inside._tabChangePerChart(e, F_Activity_Info._init[e].type, "activity")
                    } else{
                        console.log("33333333")
                        F_Activity_Info._chartHtml(e, "0", "china"),
                            M_Inside._chartTableIcon(F_Activity_Info._init[e].type, e, "0")
                    }

                }


            }
        }, function (t, a, i) {
            for (var _ = 0; _ < e.length; _++)$("#" + e[_]).html(B_Pre._empty(a))
        })
    },
    _chartHtml: function (t, a) {
        console.log("_chartHtml t:",t);
        console.log("_chartHtml a:",a);
        M_Init._dataCache["position_" + t] = a;
        var e = M_Init._dataCache.data, i = {x_axis: [], y_axis: [], yFormat: ""}, _ = {}, n = 50, o = "";
        switch (t + "") {
            case"0":
                i.xFormatDate = !0, i.yFormat = "", i.tooltip = {num: 1, unit: "人"}, o = "人";
                break;
            case"1":
            case"2":
            case"3":
                i.tooltip = {num: 1, unit: "人"}
        }
        for (var s = 0; s < F_Activity_Info._port[t][a].length; s++) {
            var r = F_Activity_Info._port[t][a][s].key.split("|"), d = F_Activity_Info._port[t][a][s].name;
            if (1 == t) {
                if (n = 20, _ = {head: ["已玩天数", "活跃玩家(人)", "玩家占比"], body: []}, e[r[0]]) {
                    for (var c = e[r[0]], y = [], h = 0; h < c.length; h++){
                        c[h].oldays_classify = c[h].oldays_classify.replace("&gt;", ">"),
                            c[h].oldays_classify = c[h].oldays_classify.replace("&lt;", "<"),
                            i.x_axis.push(c[h].oldays_classify), y.push(c[h].user_num),
                        _.body[h] || (_.body[h] = [c[h].oldays_classify]),
                            _.body[h].push(c[h].user_num), _.body[h].push(c[h].user_rate + "%");
                        i.y_axis.push({name: d, data: y})
                    }

                }
            } else if (2 == t) {
                if (n = 40, _ = {head: ["等级分布", "活跃玩家(人)", "玩家占比"], body: []}, e[r[0]]) {
                    for (var c = e[r[0]], y = [], h = 0; h < c.length; h++)i.x_axis.push(c[h].level + "级"), y.push(c[h].user_num), _.body[h] || (_.body[h] = [c[h].level + "级"]), _.body[h].push(c[h].user_num), _.body[h].push(c[h].user_rate + "%");
                    i.y_axis.push({name: d, data: y})
                }
            } else if (3 == t) {
                if (n = 20, _ = {head: ["地区", "新增玩家(人)", "玩家占比"], body: []}, e[r[0]] && e[r[0]][r[1]]) {
                    for (var c = e[r[0]][r[1]], y = [], h = 0; h < c.length; h++)i.x_axis.push(c[h].area_classify), y.push(c[h].user_num), _.body[h] || (_.body[h] = [c[h].area_classify]), _.body[h].push(c[h].user_num), _.body[h].push(c[h].user_rate + "%");
                    i.y_axis.push({name: d, data: y})
                }
                a = 0
            } else if (n = 50, _ = {
                    head: ["日期"],
                    body: []
                }, i.x_axis = e.x_axis, "%" != o ? _.head.push(d + "(" + o + ")") : _.head.push(d), e[r[0]]) {
                for (var c = e[r[0]], h = 0; h < c.length; h++)_.body[h] || (_.body[h] = [e.x_axis[h]]), "%" != o ? _.body[h].push(c[h]) : _.body[h].push(c[h] + o);
                i.y_axis.push({name: d, data: c})
            }
        }
        if (F_Activity_Info._avg[t] && F_Activity_Info._avg[t][a]) {
            console.log('3333333平均')
            for (var l = "", f = F_Activity_Info._avg[t][a], p = 0; p < f.length; p++){
                f[p].label && (l += "<span>" + f[p].label + "</span>"), l += "<span>" + f[p].name + "<b>",
                    r = f[p].key.split("|"), e[r[0]] && (l += e[r[0]]), l += f[p].unit + "</b></span>";
            }
            M_Inside._avgHtml(t + "_0", l)
        }
        _.name = M_Inside._tableName(F_Activity_Info._init, t, a, M_Init._dateCache.begin, M_Init._dateCache.end),
            a = 0, M_Init._dataCache[t + "_" + a] = _,
            M_Inside_Chart._chartData(n, "bs_chart_" + t + "_" + a, i),
            M_Inside._tableHtml(1, t + "_" + a)
    }
};
